Imports System.Data.SqlClient
Imports System.Drawing
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Repository

'--- Created Date On : 18-Nov-2010 (Gyana)

Public Class frmRptItemsReorder
    Dim mblnActivate As Boolean = False

    Private Sub frmRptItemsReorder_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        If mblnActivate = False Then
            Call PopulateLookupDX(lkCategory, "Category", "CategoryId", "tblCategory", "CategoryId,Category", "IsFixed=0", "Category", True)
            lkCategory.ItemIndex = 0
            Call PopulateData()
            mblnActivate = True
        End If
    End Sub

    Private Sub frmRptItemsReorder_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.F5 Then
            Call PopulateData()
        End If
    End Sub
    Private Sub frmRptItemsReorder_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call SetImageControl(Me)
        Call GetAccessPermission(Me, "frmRptItemsReorder")
    End Sub

    Private Sub PopulateData()
        Dim strQuery As String
        Dim dsTemp As DataSet
        Try
            strQuery = "Select ItemId [record_id],ItemCode [Item #],BarCodeNo [Bar Code #],ItemName [Item Name]" & _
                        " ,Category,ManufacturerName [Manufacturer],VendorName [Vendor],PurchaseUnit [Purchase Unit]" & _
                        " ,PurchaseUnitCost [Cost],ReOrderPoint [Re-order Point],QOH [Qty On Hand],ReOrderQty [Re-order Qty]" & _
                        " From vwItemDetails Where IsNull(QOH,0)<=IsNull(ReOrderPoint,0)" & _
                        IIf(Val(lkCategory.EditValue) <= 0, "", " And CategoryId=" & lkCategory.EditValue)
            dsTemp = FillDataSet(strQuery)
            With grdRecords
                .BeginUpdate()
                .DataSource = dsTemp.Tables(0)
                .EndUpdate()
            End With
            With gdvRecords
                .OptionsBehavior.Editable = False
                .Columns("record_id").Visible = False
                .Columns("record_id").OptionsColumn.ShowInCustomizationForm = False

                .Columns("Item Name").SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Count, "Total {0} Record(s)")
                .Columns("Cost").SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Sum, "{0:0.00}")
                .Columns("Re-order Point").SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Sum, "{0:0}")
                .Columns("Re-order Qty").SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Sum, "{0:0}")
                .Columns("Qty On Hand").SummaryItem.SetSummary(DevExpress.Data.SummaryItemType.Sum, "{0:0}")
                .BestFitColumns()
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                 Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
        GC.Collect()
    End Sub

    Private Sub lkCategory_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkCategory.EditValueChanged
        If mblnActivate = True Then Call PopulateData()
    End Sub

    Private Sub lkCategory_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles lkCategory.ButtonClick
        If e.Button.Index = 1 Then
            Call PopulateLookupDX(lkCategory, "Category", "CategoryId", "tblCategory", "CategoryId,Category", "IsFixed=0", "Category", True)
        End If
    End Sub

    Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Call ShowItemstobeReorderReport(Val(lkCategory.EditValue), Me.ParentForm)
    End Sub

    Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilter.Click
        Call PopulateData()
    End Sub
End Class
